<template>
	<MkPanel title="患者信息">
		<template #header>
			<span>患者信息</span>
			<MkHuanZheLiShi :huanZheId="model.huanZheId" :zhuYuanHao="model.zhuYuanHao" ref="liShiRef" />
		</template>
		<MkForm :model="model" :col="4" formId="traHuanZheXinXi" ref="huanZheRef">
			<MkPatient v-model="model" :isEdit="isEdit" @getPatientSuccess="getPatientSuccess"
				@editPatientInfo="editPatientInfo" ref="mkPatientRef" />
			<MkInput v-model="model.linChuangZhenDuan" prop="linChuangZhenDuan" label="诊断" :isEdit="isEdit" :col="2" />
			<MkInput v-model="model.iCDBianMa" prop="iCDBianMa" label="ICD诊断码" :isEdit="isEdit" />
			<el-row>
				<MkInputTwo label="身高" label2="体重" prop="shenGao" prop2="tiZhong">
					<template #input1>
						<el-input-number prop="shenGao" v-model="model.shenGao" :disabled="!isEdit" style="width: 100%" :min="30"
							:max="300" :controls="false">
							<template #suffix> cm </template>
						</el-input-number>
					</template>
					<template #input2>
						<el-input-number prop="tiZhong" v-model="model.tiZhong" :disabled="!isEdit" style="width: 100%" :min="2"
							:max="300" :controls="false">
							<template #suffix> kg </template>
						</el-input-number>
					</template>
				</MkInputTwo>
				<MkSelect v-model="model.tongYiShu" prop="tongYiShu" label="同意书" :options="['是', '否',]" :isEdit="isEdit" />
			</el-row>
			<el-row>
				<MkSelect v-model="model.shuXueShi" prop="shuXueShi" label="输血史" :options="['有', '无',]" :isEdit="isEdit"
					allow-create />
				<MkSelect v-model="model.shuXueFanYingShi" prop="shuXueFanYingShi" label="输血反应史" :options="['有', '无',]"
					:isEdit="isEdit" />
				<MkSelectEdit label="孕产史" prop="yunChanShi" :isEdit="isEdit" v-model="model.yunChanShi"
					:options="[{ title: '无', canEdit: false, }, { title: '有 , 孕 x, 产 x', canEdit: true, }]"
					v-if="model.xingBie == enumCode.Gender.女">
				</MkSelectEdit>
				<MkSelectEdit label="移植史" prop="yiZhiShi" :isEdit="isEdit" v-model="model.yiZhiShi" :col="2"
					:options="[{ title: '无', canEdit: false, }, { title: '有 , 移植日期: xx年x月x日 , 供者血型: ABO / Rh(D)', canEdit: true, }]"
					selectId="editHuanZhe_yiZhiShi">
				</MkSelectEdit>
			</el-row>
		</MkForm>
	</MkPanel>
</template>
<script lang="ts" setup>
/* 患者信息
输血史,反应史,移植史,孕产史都需要修改为可以输入的下拉框, 
反应史,移植史 结果不是无或空, 输入框背景需要高亮
是否签署同意书应该从his获取,如果没有默认否,保存单据是需要判断,为否是需要弹框询问是否已经签署,点击"已签署"则自动修正并提交单据
患者是历史输血等历史信息需要异步获取,点击后可以弹框显示
*/
import { TraShenQingApi, TraShenQingHuanZheInput, TraShenQingYongXueInput } from '/@/api/tra/TraShenQing';
import { enumCode } from '/@/const';
import { isNull } from '/@/utils';

const props = defineProps({
	isEdit: {
		type: Boolean,
		default: true,
	}
})

const emits = defineEmits(['getPatientSuccess', 'getPatientFail', 'editPatientInfo'])

const model = defineModel({ required: true, default: {} as TraShenQingHuanZheInput })
const huanZheRef = ref()
const liShiRef = ref()

// 历史次数
const getLiShiCiShu = () => {
	liShiRef.value.getLiShiCiShu()
}

//#region MkPatient组件的处理事件 
// 获取患者信息成功后的回调事件
const getPatientSuccess = () => {
	if (isNull(model.value.tongYiShu)) {
		model.value.tongYiShu = '否'
	}
	// 获取患者最新的历史信息
	TraShenQingApi.checkHuanZheLatestInfo({ huanZheId: model.value.huanZheId, zhuYuanHao: model.value.zhuYuanHao }).then(res => {
		const fields = ['shuXueShi', 'shuXueFanYingShi', 'yunChanShi', 'yiZhiShi', 'fuHeABO', 'fuHeRhD', 'kangShaiJieGuo'];
		fields.forEach(field => {
			// wcf有返回值，就不覆盖
			if (isNull(model.value[field])) {
				model.value[field] = res[field];
			}
		});
	})
	// 获取检验结果
	emits('getPatientSuccess')
	// 获取次数
	getLiShiCiShu()
}
/** 弹框修改患者信息 */
const editPatientInfo = () => {
	emits('editPatientInfo')
}
const mkPatientRef = ref()
const patientInpFocus = () => {
	nextTick(() => {
		mkPatientRef.value.inputFocus()
	})
}
//#endregion 
const validate = async () => {
	return await huanZheRef.value.validate()
}

defineExpose({ patientInpFocus, validate })
</script>

<style lang="scss" scoped></style>
